<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Article;
use App\Models\Traits\Recommend;

class House extends Model
{
    use HasFactory, Recommend;

    protected $fillable =
        ['id', 'description', 'template',
            'title', 'content', 'preview', 'images',
            'url', 'source', 'click', 'keywords',
            'author', 'article_id', 'recommend', 'extra'];
    protected $casts = ['extra' => 'array', 'images' => 'array'];


    protected $appends = ['cname'];


    protected function getCnameAttribute()
    {
        return class_basename($this);
    }

    public function article()
    {
        return $this->belongsTo(Article::class);
    }


//搜索
    public
    function scopeWord($query, $word)
    {
        return $query->where('title', 'like', "%" . $word . "%")->get();
    }

}
